
import {  ADD_TODO, DELETE_TODO } from "../actions";
import { combineReducers } from 'redux'



const initialState = [
    {
      text: 'Use Redux',
      completed: false,
      id: 0
    }
  ]
  
const todos = (state=initialState,action)=>{
    switch (action.type) {
        case ADD_TODO:
            return [
                ...state,
                {
                    id:state.reduce((maxId,todo)=>Math.max(maxId,todo.id),0) +1 ,
                    completed:false,
                    text:action.text
                }
            ]
            break;
    
        default:
        return state
            break;
    }
}
 
const reducer = combineReducers({
    todos
  })

export default reducer